function get_server_info() {
    var msg = request.body(true);
    var res = resource.actionMsgByString(msg);
    if (res.error != 0) {
        return res;
    }

    res = resource.rsaDecryptCSharp(res.content, privateKey);
    if (res.error != 0) {
        return res;
    }
   
    var ip = request.ip();
    var dd = JSON.parse(res.value);
    var type = dd.type;
    if (type != 2) {
        type = 1;
    }

    var value;
    if (type == 1) {
        value = ip;
    } else {
        value = dd.value;
    }

    var tag = dd.tag;
    if (tag === undefined) {
        tag = null;
    }

    var where;
    if (tag === null) {
        where = "ip='" + value + "'";
    }
    else {
        where = "ip='" + value + "' and tag like '%" + tag + "%'";
    }

   

    res = data.select("yqbase", "licServer", where, "");
    if (res.error != 0) {
        return res;
    }
    if (res.rows.length == 0) {
        return {
            error: 100,
            info: "服务[" + value + "]未注册. 请登录 www.yqsite.com 进行注册。"
        }
    }

    var row = res.rows[0];

    // 检查是否已注销
    if (row.isdel === true) {
        update_link(row.sid, 101, ip)
        return {
            error: 101,
            info: "服务[" + ip + "]注销状态，请登录 www.yqsite.com 续期服务。"
        }
    }
    row.duedate = row.duedate.split(' ')[0]; // 只取日期部分

    // 检查是否已到期
    var duedate = new Date(row.duedate);
    var currentDate = new Date();
    if (currentDate > duedate) {
        var duedateStr = row.duedate.split(' ')[0]; // 只取日期部分
        update_link(row.sid, 102, ip)
        return {
            error: 102,
            info: "服务[" + ip + "]已过期[" + duedateStr + "]，请登录 www.yqsite.com 续期服务。"
        }
    }

    if (row.checkdomain) {
        if (row.domainname === undefined ||
            row.domainname === null ||
            row.domainname === "") {
            update_link(row.sid, 100, ip)
            return {
                error: 103,
                info: "服务[" + ip + "]未注册域名. 请登录 www.yqsite.com 进行注册。"
            }
        }

        res = resource.domain2ip(row.domainname);
        if (res.error != 0) {
            update_link(row.sid, 103, ip)
            return res;
        }
        if (res.value != row.ip) {
            update_link(row.sid, 103, ip)
            return {
                error: 103,
                info: "服务[" + ip + "]域名[" + row.domainname + "]解析IP[" + res.value + "]与注册IP[" + row.ip + "]不一致. 请登录 www.yqsite.com 进行注册。"
            }
        }
    }

    row.error = 0;
    row.domainName = row.domainname;
    row.checkDomain = row.checkdomain;
    row.appDate = row.appdate.split(' ')[0];
    row.dueDate = row.duedate.split(' ')[0];
    if (row.mark === undefined) {
        row.mark = null;
    }

    delete row.domainname;
    delete row.checkdomain;
    delete row.appdate;
    delete row.duedate;
    delete row.stamp;

    var jsonString = JSON.stringify(row);
    var sign = sFingerPrint(jsonString);
    var result = jsonString.substring(0, jsonString.length - 1) + ',"sign":"' + sign.toUpperCase() + '"}';

    //row.sign = sFingerPrint(row.mark === null ? "" : row.mark, row.duedate.split(' ')[0], row.tag);

    update_link(row.sid, 0, ip)
    return {
        error: 0,
        info: "success",
        value: result
    }
}

function update_link(sid, error, ip) {
    var checktime = resource.timeToISOString(new Date());

    var res = data.action("yqbase", "licServer", [{
        "action": "upp_",
        row: {
            "sid": sid,
            "checkcorrect": error,
            "checktime": checktime
        }
    }]);
    if (res.error != 0) {
        return res;
    }

    res = data.action("yqbase", "licServerLog", [{
        "action": "add",
        row: {
            "pid": sid,
            "checkcorrect": error,
            "checktime": checktime,
            "ip": ip
        }
    }]);

    return res;
}

function sFingerPrint(text) {
    try {
        const res = resource.stringToMD5(text);
        if (res.error == 0) {
            return res.value;
        } else {
            return "@error:" + res.info;
        }
    } catch (ex) {
        return Promise.resolve("@error:" + ex.message);
    }
}